package com.ehualu.liaocheng.until;

import com.ehualu.liaocheng.config.ProFileConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {


    static Connection con1 = null;
    static Connection con2 = null;

    public static Connection gethkdb() {


        try {
            Class.forName(ProFileConfig.driver);
//			System.out.println("mysql driver load successfully!");
            con1 = DriverManager.getConnection(ProFileConfig.jdbcurl,
                    ProFileConfig.username, ProFileConfig.password);
            System.out.println("hk db Connection create!");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return con1;
    }


    public static Connection getehldb() {


        try {
            Class.forName(ProFileConfig.driver);
//			System.out.println("mysql driver load successfully!");
            con2 = DriverManager.getConnection(ProFileConfig.YDZSjdbcurl,
                    ProFileConfig.YDZSusername, ProFileConfig.YDZSpassword);
            System.out.println("ehl db Connection create!");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return con2;
    }


    public static Connection getcon(int conid) {

        if (conid == 1) {
            if (con1 == null) {

                gethkdb();

            }
            return con1;

        } else {

            if (con2 == null) {

                getehldb();
            }
            return con2;

        }

    }


}
